package com.cloudlead.common.lang.api;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAnyElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * 默认响应
 *
 * @author dean.lu
 */
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class SimpleActionResponse<T> extends AbstractActionResponse {

    @XmlAnyElement
    protected T content;

    protected String message;

    public SimpleActionResponse() {
        this(null);
    }

    public SimpleActionResponse(boolean success, Level level) {
        this(success, level, null, ResponseCode.OK.code(), ResponseCode.OK
                .reason());
    }

    public SimpleActionResponse(T content) {
        this(true, Level.info, content, ResponseCode.OK.code(), ResponseCode.OK
                .reason());
    }

    public SimpleActionResponse(boolean success, Level level, T content,
                                int code, String message) {
        super(success, level);
        this.content = content;
        this.code = code;
        this.message = message;
    }

    public T getContent() {
        return content;
    }

    public void setContent(T content) {
        this.content = content;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    /**
     *
     */
    private static final long serialVersionUID = -3283875599232873467L;

    @Override
    public String toString() {
        return String
                .format("SimpleActionResponse {success:%s, level:%s, takeTime:%s,requestId:%s,code:%s, content:%s, message:%s}",
                        success, level, takeTime, requestId, code, content, message);
    }

}
